package com.cqndt.disaster.device.controller;

import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import com.cqndt.disaster.device.util.Result;
import com.cqndt.disaster.device.vo.TabUserVo;
import com.cqndt.disaster.device.vo.TabAlarmInfoVo;
import org.springframework.web.bind.annotation.PostMapping;
import com.cqndt.disaster.device.service.TabAlarmInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgb
 * @date 2020-8-29
 * @说明 告警管理
 **/
@RestController
@RequestMapping("/tabAlarm")
public class TabAlarmController extends BaseController{
	
    @Autowired
    private TabAlarmInfoService tabAlarmInfoService;

    /**
     * @param areaCode 区域编码
     * @param level 区域等级
     * @param projectId 项目id
     * @param deviceName 设备名称
     * @param alarmType 告警类型
     * @param warmLevel 告警等级
     * @param deviceName 设备名称
     * @return
     **/
    @PostMapping(value="listTabAlarmInfo")
    public Result listTabAlarmInfo(TabAlarmInfoVo vo){
        TabUserVo userVo = getCurrentUser();
        vo.setUserId(userVo.getId());
        if(null == vo.getLevel()){
            vo.setAreaLevel(userVo.getLevel());
            vo.setAreaCode(userVo.getAreaCode());
        }else{
            vo.setAreaLevel(vo.getLevel().toString());
            vo.setAreaCode(vo.getAreaCode());
        }
        PageHelper.startPage(vo.getPage(),vo.getLimit());
        PageInfo<TabAlarmInfoVo> pageInfo = new PageInfo<TabAlarmInfoVo>(
        		tabAlarmInfoService.listTabAlarmInfo(vo));
        Result result = new Result();
        result.setCount((int)pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }
    /**
     * @param id 告警id
     * @return 根据告警id查询告警详情
     **/
    @PostMapping(value="getDetailById")
    public Result getDetailById(String id){
        TabAlarmInfoVo infoVo = tabAlarmInfoService.getDetailById(id);
        Result result = new Result();
        result.setData(infoVo);
        return result;
    }
    
    /**
     * @param monitorId 监测点id
     * @return 根据监测点id查询告警详情
     **/
    @PostMapping(value="getDetailByMonitorId")
    public Result getDetailByMonitorId(TabAlarmInfoVo vo){
        TabUserVo userVo = getCurrentUser();
        vo.setUserId(userVo.getId());
        vo.setAreaLevel(userVo.getLevel());
        vo.setAreaCode(userVo.getAreaCode());
        TabAlarmInfoVo infoVo = tabAlarmInfoService.getDetailByMonitorId(vo);
        Result result = new Result();
        result.setData(infoVo);
        return result;
    }
    
}